package tt.dz.order.pojo;

import java.util.HashMap;
import java.util.Map;

import tt.dz.order.dao.BaseDAOUtil;
import tt.dz.order.util.OrderConstant.CardType;

/**
 * @Title 用户信息，订单服务器这边只做查询
 * @author zhoutian   
 * @date 2015-11-26
 */
public class UserInfo {
	//用户ID
	private String userId;
	//用户类型； 0 个人客户,1 企业客户,2 支持统付的个人客户
	private Integer userType;
	//用户所属的运营商
	private String merchantCode;

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Integer getUserType() {
		return userType;
	}

	public void setUserType(Integer userType) {
		this.userType = userType;
	}

	public String getMerchantCode() {
		return merchantCode;
	}

	public void setMerchantCode(String merchantCode) {
		this.merchantCode = merchantCode;
	}
	
	public UserInfo() {}
	
	public static UserInfo getById(String userId){
		String sql = "select user_id as userId, user_type as userType, merchant_code as merchantCode from ms_user_base where user_id = :userId";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("userId", userId);
		return BaseDAOUtil.queryForObject(sql, paramMap, UserInfo.class);
	}
	
	public static UserInfo getUserInfoBy(String cardType, String cardNo){
		if(cardType.equals(CardType.OFFLINE_CARD.value())){
			return null;
		}
		String sql = null;
		if(cardType.equals(CardType.ONLINE_CARD.value())){
			sql = "select ub.user_id as userId, ub.user_type as userType, ub.merchant_code as merchantCode from ms_user_base ub INNER JOIN ms_online_account ona on ub.user_id = ona.user_id where ona.card_no = :cardNo";
		} else if(cardType.equals(CardType.IDENTITY_CARD.value())){
			sql = "select ub.user_id as userId, ub.user_type as userType, ub.merchant_code as merchantCode from ms_user_base ub INNER JOIN ms_identity_account ia on ub.user_id = ia.user_id where ia.card_no = :cardNo";
		}
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("cardNo", cardNo);
		return BaseDAOUtil.queryForObject(sql, paramMap, UserInfo.class);
	}
}
